/*
 * 项目名称:platform-plus
 * 类名称:SysJmCourseOrgServiceImpl.java
 * 包名称:com.platform.modules.sys.service.impl
 *
 * 修改履历:
 *     日期                       修正者        主要内容
 *     2021-07-01 12:52:53        oubijie     初版做成
 *
 * Copyright (c) 2019-2019 klwu
 */
package com.platform.modules.sys.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.platform.common.utils.Query;
import com.platform.modules.sys.dao.SysJmCourseOrgDao;
import com.platform.modules.sys.entity.SysJmCourseOrgEntity;
import com.platform.modules.sys.form.SysJmCourseOrgForm;
import com.platform.modules.sys.service.SysJmCourseOrgService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * Service实现类
 *
 * @author oubijie
 * @date 2021-07-01 12:52:53
 */
@Service("sysJmCourseOrgService")
public class SysJmCourseOrgServiceImpl extends ServiceImpl<SysJmCourseOrgDao, SysJmCourseOrgEntity> implements SysJmCourseOrgService {

    @Override
    public List<SysJmCourseOrgEntity> queryAll(Map<String, Object> params) {
        return baseMapper.queryAll(params);
    }

    @Override
    public Page queryPage(Map<String, Object> params) {
        //排序
        params.put("sidx", "T.id");
        params.put("asc", false);
        Page<SysJmCourseOrgEntity> page = new Query<SysJmCourseOrgEntity>(params).getPage();
        return page.setRecords(baseMapper.selectSysJmCourseOrgPage(page, params));
    }

    @Override
    public boolean add(SysJmCourseOrgEntity sysJmCourseOrg) {
        return this.save(sysJmCourseOrg);
    }

    @Override
    public boolean update(SysJmCourseOrgEntity sysJmCourseOrg) {
        return this.updateById(sysJmCourseOrg);
    }

    @Override
    public boolean delete(Integer id) {
        return this.removeById(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteBatch(Integer[] ids) {
        return this.removeByIds(Arrays.asList(ids));
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean addAll(SysJmCourseOrgForm form) {
        baseMapper.deleteByOrgAndModule(form.getOrg(), form.getModule());
        if(form.getTasks() != null && form.getTasks().length > 0) {
            baseMapper.insertAll(form);
        }
        return true;
    }
}
